#/usr/bin/python

import os, sys
from ivic.core.Config import *

vspace_yaml = project_path('/etc/ivic/vspace.yaml')
vm_yaml = project_path('/etc/ivic/vm.yaml')



       
def get_vm_uuid():
    try:
        conf = yaml.load(file(vm_yaml))
        return conf['uuid']
    except Exception, e:
        logger.error("error at /ivic/vspace:get_vm_uuid-> %s" % e)
        

class VSpaceConfig(object):
    
    def __init__(self,configmap = None):
        if configmap == None:
           self.config = load(vspace_yaml)
        else: self.config = configmap        
        
        self.log = self.config['log_file']
        if not os.path.exists(self.log): 
            log = open(self.log,'w')
            log.close()
        
        self.common_user = self.config['common_user']
        self.thread_num = self.config['thread_num']
        self.debug_soap = self.config['debug_soap']
        self.portal_url = self.config['monitor']['url']
        self.uuid= get_vm_uuid()  

vspace_config = VSpaceConfig()          
    
if __name__ == "__main__":
    
    #make sure add logdir and log File created and chmod 0777
    #just For local test.
    logdir = '/var/log/ivic/'
    log = '/var/log/ivic/config.log'

    sys.path.insert(0, os.getcwd())
    
    from ivic.core.Config import *
    ivic.core.set_rundebug()
        
    config = VSpaceConfig()
    print config.common_user,config.monitor_url,config.thread_num,config.debug_soap